package com.ly.datacenter.http.util;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ly.datacenter.database.definition.HttpParameter4DatabaseCRUD;

/**
 * function:
 * @author watson  email: watson.wu@hotmail.com
 * @date 2009-9-2
 */
public class HttpServletUtil {

	/**
	 * 
	 * function:
	 * @param request
	 * @param response
	 */
	public static void configResponseJSON(HttpServletRequest request, HttpServletResponse response){
		response.setHeader("Cache-Control", "nocache");
		response.setContentType("application/json;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Connection", "Keep-Alive");
	}

	/**
	 * 
	 * function:
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static Map getParameters(HttpServletRequest request) {
		Map conditions = new HashMap();
		Enumeration parameterNames = request.getParameterNames();
		while(parameterNames.hasMoreElements()) {
			String ele = parameterNames.nextElement().toString();
			if(HttpParameter4DatabaseCRUD.has(ele) || ele == null)
				continue;
			conditions.put(ele, request.getParameter(ele));
		}
		return conditions;
	}

}

